package jmind.core.util;

public class AppEnvironment {

    private static final String APP_ENV = "app.env";

    public static final String TEST = "test";
    public static final String PRODUCTION = "production";

    public static void setEnvironment(String env) {
        System.setProperty(APP_ENV, env);
    }

    /**
     * 获取当前环境
     * @return
     */
    public static String getEnvironment() {
        // 优先 -DLETV_ENV=test
        String environment = System.getProperty(APP_ENV);
        // export LETV_ENV=production
        if (DataUtil.isEmpty(environment))
            environment = System.getenv(APP_ENV);
        // 再次 ，根据ip 判断
        if (DataUtil.isEmpty(environment)) {
            return TEST;
        }
        return environment.toLowerCase();
    }

    /**
     *  是否测试环境
     * @return
     */
    public static boolean isTest() {
        return getEnvironment().startsWith(TEST);
    }

    public static boolean isProduction() {
        return getEnvironment().startsWith(PRODUCTION);
    }

}
